<template>
  <div>
    <Yq-header :needBack="true">
      <p slot="content" style="margin-left: -12px">分销记录</p>
    </Yq-header>
    <group gutter="0" style="padding-top: 38px;">
      <cell v-for="item in distributionList" :title="item.name + '通过您分享的链接在平台消费'" :inline-desc="item.insertTime">
        <span class="money" v-if="item.type===2">{{item.amount}}积分</span>
        <span class="money" v-if="item.type===1">￥{{item.amount}}</span>
      </cell>
    </group>
    <div v-if="noList===true" style="text-align: center;line-height: 150px;color: #636363;">暂无分销记录</div>
  </div>
</template>

<script>
  import { Group, Cell, XButton } from 'vux'
  import * as urls from '../../../../api/urls'
  import YqHeader from '../../../../components/YqHeader.vue'

  export default {
    components: {
      Group,
      Cell,
      XButton,
      YqHeader
    },
    data () {
      return {
        noList: false,
        distributionList: [
        ]
      }
    },
    methods: {
      weixinfn27 () {
        let that = this
        let userId = window.sessionStorage.getItem('userId')
        let logo = window.sessionStorage.getItem('LOGO')
        let url = window.location.origin
        let link = url + '/api/wxAuth/index?type=t1' + '&uid=' + userId
        that.$wechat.onMenuShareAppMessage({
          title: '孝行通', // 分享标题
          desc: '孝行通·微商城 一个让子女为父母尽孝的老年服务平台', // 分享描述
          link: link, // 分享链接
          imgUrl: logo, // 分享图标
          success: function () {
            // 用户确认分享后执行的回调函数
          },
          cancel: function () {
            // 用户取消分享后执行的回调函数
          }
        })
        that.$wechat.onMenuShareTimeline({
          title: '孝行通', // 分享标题
          link: link, // 分享链接
          imgUrl: logo, // 分享图标
          success: function () {
            // 用户确认分享后执行的回调函数
          },
          cancel: function () {
            // 用户取消分享后执行的回调函数
          }
        })
      },
      getDisList () {
        let userId = window.sessionStorage.getItem('userId')
        let that = this
        that.http(urls.spreadList, {userId: userId}, function (res) {
          if (res.status === 100) {
            that.distributionList = res.data.page.list
            if (that.distributionList.length === 0) {
              that.noList = true
            } else {
              that.noList = false
            }
          } else {
            that.show = true
            that.message = res.errMsg
          }
        }, function (res) {
          that.show = true
          that.message = res.errMsg
        })
      }
    },
    mounted: function () {
      this.getDisList()
      this.weixinfn27()
    }
  }
</script>

<style scoped="scoped">
  .money{
    color: #636363;
    font-weight: bold;
    font-size: 15px;
  }
</style>
